﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;

namespace SMG.Presentation
{
    public class CrudButtonResolver
    {
        public static void SetStateEditing(List<Button> buttons)
        {
            Button button = buttons.Where(q => q.Name.Equals("btnNovo")).FirstOrDefault();
            if(button != null)
                button.Visibility = Visibility.Collapsed;

            button = buttons.Where(q => q.Name.Equals("btnAlterar")).FirstOrDefault();
            if (button != null)
                button.Visibility = Visibility.Collapsed;

            button = buttons.Where(q => q.Name.Equals("btnCancelar")).FirstOrDefault();
            if (button != null)
                button.Visibility = Visibility.Visible;

            button = buttons.Where(q => q.Name.Equals("btnConsultar")).FirstOrDefault();
            if (button != null)
                button.Visibility = Visibility.Collapsed;

            button = buttons.Where(q => q.Name.Equals("btnExcluir")).FirstOrDefault();
            if (button != null)
                button.Visibility = Visibility.Collapsed;

            button = buttons.Where(q => q.Name.Equals("btnSalvar")).FirstOrDefault();
            if (button != null)
                button.Visibility = Visibility.Visible;

            button = buttons.Where(q => q.Name.Equals("btnSair")).FirstOrDefault();
            if (button != null)
                button.Visibility = Visibility.Collapsed;
        }

        public static void SetStateLoaded(List<Button> buttons)
        {
            Button button = buttons.Where(q => q.Name.Equals("btnNovo")).FirstOrDefault();
            if (button != null)
                button.Visibility = Visibility.Visible;

            button = buttons.Where(q => q.Name.Equals("btnAlterar")).FirstOrDefault();
            if (button != null)
                button.Visibility = Visibility.Visible;

            button = buttons.Where(q => q.Name.Equals("btnCancelar")).FirstOrDefault();
            if (button != null)
                button.Visibility = Visibility.Collapsed;

            button = buttons.Where(q => q.Name.Equals("btnConsultar")).FirstOrDefault();
            if (button != null)
                button.Visibility = Visibility.Visible;

            button = buttons.Where(q => q.Name.Equals("btnExcluir")).FirstOrDefault();
            if (button != null)
                button.Visibility = Visibility.Visible;

            button = buttons.Where(q => q.Name.Equals("btnSalvar")).FirstOrDefault();
            if (button != null)
                button.Visibility = Visibility.Collapsed;

            button = buttons.Where(q => q.Name.Equals("btnSair")).FirstOrDefault();
            if (button != null)
                button.Visibility = Visibility.Visible;
        }

        public static void SetStateBlank(List<Button> buttons)
        {
            Button button = buttons.Where(q => q.Name.Equals("btnNovo")).FirstOrDefault();
            if (button != null)
                button.Visibility = Visibility.Visible;

            button = buttons.Where(q => q.Name.Equals("btnAlterar")).FirstOrDefault();
            if (button != null)
                button.Visibility = Visibility.Collapsed;

            button = buttons.Where(q => q.Name.Equals("btnCancelar")).FirstOrDefault();
            if (button != null)
                button.Visibility = Visibility.Collapsed;

            button = buttons.Where(q => q.Name.Equals("btnConsultar")).FirstOrDefault();
            if (button != null)
                button.Visibility = Visibility.Visible;

            button = buttons.Where(q => q.Name.Equals("btnExcluir")).FirstOrDefault();
            if (button != null)
                button.Visibility = Visibility.Collapsed;

            button = buttons.Where(q => q.Name.Equals("btnSalvar")).FirstOrDefault();
            if (button != null)
                button.Visibility = Visibility.Collapsed;

            button = buttons.Where(q => q.Name.Equals("btnSair")).FirstOrDefault();
            if (button != null)
                button.Visibility = Visibility.Visible;
        }
    }
}
